package com.gitee.feizns.explore.data_structure.recursive.memoization;

import java.util.HashMap;
import java.util.Map;

/**
 * @author feizns
 * @since 2019/12/10
 */
public class Fib {

    public static void main(String[] args) {
        System.out.println(fib(32));
    }

    private static Map<Integer, Integer> cache = new HashMap<>();

    static {
        cache.put(0, 0);
        cache.put(1, 1);
    }

    public static int fib(int n) {
        Integer ret = cache.get(n);
        if ( ret == null ) {
            ret = fib(n - 1) + fib(n - 2);
            cache.put(n, ret);
        }
        return ret;
    }

}
